Public Class ZoomControl
    Inherits System.Windows.Forms.UserControl

    Const SCROLLVALUE = 50

    Private mvarXOff As Single
    Private mvarYOff As Single
    Private mvarxyScale As Single = 1

    Private mvarMinimumX As Single = -1600
    Private mvarMinimumY As Single = -1800
    Private mvarMaximumX As Single = 1800
    Private mvarMaximumY As Single = 1600

    Public Event ScaleScrollChange()

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'UserControl overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents pnlStuff As System.Windows.Forms.Panel
    Friend WithEvents btnUp As System.Windows.Forms.Button
    Friend WithEvents btnDown As System.Windows.Forms.Button
    Friend WithEvents btnRight As System.Windows.Forms.Button
    Friend WithEvents btnLeft As System.Windows.Forms.Button
    Friend WithEvents opt50 As System.Windows.Forms.RadioButton
    Friend WithEvents opt200 As System.Windows.Forms.RadioButton
    Friend WithEvents opt100 As System.Windows.Forms.RadioButton
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents picOverview As System.Windows.Forms.PictureBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(ZoomControl))
        Me.btnUp = New System.Windows.Forms.Button()
        Me.btnDown = New System.Windows.Forms.Button()
        Me.btnRight = New System.Windows.Forms.Button()
        Me.btnLeft = New System.Windows.Forms.Button()
        Me.pnlStuff = New System.Windows.Forms.Panel()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.picOverview = New System.Windows.Forms.PictureBox()
        Me.Label1 = New System.Windows.Forms.Label()
        Me.opt200 = New System.Windows.Forms.RadioButton()
        Me.opt50 = New System.Windows.Forms.RadioButton()
        Me.opt100 = New System.Windows.Forms.RadioButton()
        Me.pnlStuff.SuspendLayout()
        Me.SuspendLayout()
        '
        'btnUp
        '
        Me.btnUp.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnUp.Image = CType(resources.GetObject("btnUp.Image"), System.Drawing.Bitmap)
        Me.btnUp.Location = New System.Drawing.Point(54, 152)
        Me.btnUp.Name = "btnUp"
        Me.btnUp.Size = New System.Drawing.Size(32, 23)
        Me.btnUp.TabIndex = 7
        '
        'btnDown
        '
        Me.btnDown.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnDown.Image = CType(resources.GetObject("btnDown.Image"), System.Drawing.Bitmap)
        Me.btnDown.Location = New System.Drawing.Point(54, 200)
        Me.btnDown.Name = "btnDown"
        Me.btnDown.Size = New System.Drawing.Size(32, 23)
        Me.btnDown.TabIndex = 8
        '
        'btnRight
        '
        Me.btnRight.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnRight.Image = CType(resources.GetObject("btnRight.Image"), System.Drawing.Bitmap)
        Me.btnRight.Location = New System.Drawing.Point(94, 176)
        Me.btnRight.Name = "btnRight"
        Me.btnRight.Size = New System.Drawing.Size(32, 23)
        Me.btnRight.TabIndex = 9
        '
        'btnLeft
        '
        Me.btnLeft.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnLeft.Image = CType(resources.GetObject("btnLeft.Image"), System.Drawing.Bitmap)
        Me.btnLeft.Location = New System.Drawing.Point(14, 176)
        Me.btnLeft.Name = "btnLeft"
        Me.btnLeft.Size = New System.Drawing.Size(32, 23)
        Me.btnLeft.TabIndex = 10
        '
        'pnlStuff
        '
        Me.pnlStuff.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.pnlStuff.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label2, Me.picOverview, Me.Label1, Me.opt200, Me.opt50, Me.opt100, Me.btnRight, Me.btnUp, Me.btnLeft, Me.btnDown})
        Me.pnlStuff.Location = New System.Drawing.Point(8, 8)
        Me.pnlStuff.Name = "pnlStuff"
        Me.pnlStuff.Size = New System.Drawing.Size(238, 236)
        Me.pnlStuff.TabIndex = 11
        '
        'Label2
        '
        Me.Label2.BackColor = System.Drawing.SystemColors.InactiveCaption
        Me.Label2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.Label2.Location = New System.Drawing.Point(152, 152)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(16, 72)
        Me.Label2.TabIndex = 17
        Me.Label2.Text = "ZOOM"
        Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'picOverview
        '
        Me.picOverview.BackColor = System.Drawing.Color.Black
        Me.picOverview.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.picOverview.Location = New System.Drawing.Point(8, 8)
        Me.picOverview.Name = "picOverview"
        Me.picOverview.Size = New System.Drawing.Size(216, 136)
        Me.picOverview.TabIndex = 16
        Me.picOverview.TabStop = False
        '
        'Label1
        '
        Me.Label1.AutoSize = True
        Me.Label1.Location = New System.Drawing.Point(54, 180)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(27, 13)
        Me.Label1.TabIndex = 15
        Me.Label1.Text = "PAN"
        Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'opt200
        '
        Me.opt200.Appearance = System.Windows.Forms.Appearance.Button
        Me.opt200.BackColor = System.Drawing.Color.LightGray
        Me.opt200.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.opt200.Location = New System.Drawing.Point(167, 200)
        Me.opt200.Name = "opt200"
        Me.opt200.Size = New System.Drawing.Size(56, 24)
        Me.opt200.TabIndex = 14
        Me.opt200.Text = "200%"
        Me.opt200.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'opt50
        '
        Me.opt50.Appearance = System.Windows.Forms.Appearance.Button
        Me.opt50.BackColor = System.Drawing.Color.LightGray
        Me.opt50.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.opt50.Location = New System.Drawing.Point(167, 152)
        Me.opt50.Name = "opt50"
        Me.opt50.Size = New System.Drawing.Size(56, 24)
        Me.opt50.TabIndex = 12
        Me.opt50.Text = "50%"
        Me.opt50.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'opt100
        '
        Me.opt100.Appearance = System.Windows.Forms.Appearance.Button
        Me.opt100.BackColor = System.Drawing.Color.LightBlue
        Me.opt100.Checked = True
        Me.opt100.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.opt100.Location = New System.Drawing.Point(167, 175)
        Me.opt100.Name = "opt100"
        Me.opt100.Size = New System.Drawing.Size(56, 26)
        Me.opt100.TabIndex = 13
        Me.opt100.TabStop = True
        Me.opt100.Text = "100%"
        Me.opt100.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'ZoomControl
        '
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.pnlStuff})
        Me.Name = "ZoomControl"
        Me.Size = New System.Drawing.Size(256, 264)
        Me.pnlStuff.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region

    Public Sub ApplyTransforms(ByRef gr As Graphics)
        ' xy coord transform
        gr.TranslateTransform(Me.XOffset, Me.YOffset)
        ' scale transform
        gr.ScaleTransform(Me.XYScale, Me.XYScale)
    End Sub

    Public Sub ApplyXYTransforms(ByRef ptrPoint As Point)
        If Me.XOffset <> 0 Then
            ptrPoint.X = ptrPoint.X - Me.XOffset
        End If
        If Me.YOffset <> 0 Then
            ptrPoint.Y = ptrPoint.Y - Me.YOffset
        End If

        ' edit for scaling
        Select Case Me.XYScale
            Case Is = 0.5
                ptrPoint.X = ptrPoint.X + (ptrPoint.X)
                ptrPoint.Y = ptrPoint.Y + (ptrPoint.Y)
            Case Is = 2
                ptrPoint.X = ptrPoint.X - (ptrPoint.X / 2)
                ptrPoint.Y = ptrPoint.Y - (ptrPoint.Y / 2)
        End Select
    End Sub

#Region "Properties"

    Public WriteOnly Property MinimumX() As Single
        Set(ByVal Value As Single)
            mvarMinimumX = Value
        End Set
    End Property

    Public WriteOnly Property MinimumY() As Single
        Set(ByVal Value As Single)
            mvarMinimumY = Value
        End Set
    End Property

    Public WriteOnly Property MaximumX() As Single
        Set(ByVal Value As Single)
            mvarMaximumX = Value
        End Set
    End Property

    Public WriteOnly Property MaximumY() As Single
        Set(ByVal Value As Single)
            mvarMaximumY = Value
        End Set
    End Property

    Public ReadOnly Property XOffset() As Single
        Get
            Return mvarXOff
        End Get
    End Property

    Public ReadOnly Property YOffset() As Single
        Get
            Return mvarYOff
        End Get
    End Property

    Public ReadOnly Property XYScale() As Single
        Get
            Return mvarxyScale
        End Get
    End Property

    Public ReadOnly Property OverviewGraphics() As Graphics
        Get
            Return picOverview.CreateGraphics
        End Get
    End Property

    Public ReadOnly Property Clip() As RectangleF
        Get
            Dim gr As Graphics = picOverview.CreateGraphics
            Return gr.VisibleClipBounds
            gr.Dispose()
        End Get
    End Property

#End Region

    Private Sub btnUp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUp.Click
        mvarYOff = mvarYOff + SCROLLVALUE
        If mvarYOff > mvarMaximumY Then mvarYOff = mvarMaximumY
        RaiseEvent ScaleScrollChange()
    End Sub

    Private Sub btnDown_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDown.Click
        mvarYOff = mvarYOff - SCROLLVALUE
        If mvarYOff < mvarMinimumY Then mvarYOff = mvarMinimumY
        RaiseEvent ScaleScrollChange()
    End Sub

    Private Sub btnRight_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRight.Click
        mvarXOff = mvarXOff - SCROLLVALUE
        If mvarXOff < mvarMinimumX Then mvarXOff = mvarMinimumX
        RaiseEvent ScaleScrollChange()
    End Sub

    Private Sub btnLeft_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLeft.Click
        mvarXOff = mvarXOff + SCROLLVALUE
        If mvarXOff > mvarMaximumX Then mvarXOff = mvarMaximumX
        RaiseEvent ScaleScrollChange()
    End Sub

    Private Sub opt50_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles opt50.CheckedChanged
        If opt50.Checked = True Then
            mvarxyScale = 2
            opt50.BackColor = Color.LightBlue
        Else
            opt50.BackColor = Color.LightGray
        End If
        RaiseEvent ScaleScrollChange()
    End Sub

    Private Sub opt100_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles opt100.CheckedChanged
        If opt100.Checked = True Then
            mvarxyScale = 1
            opt100.BackColor = Color.LightBlue
        Else
            opt100.BackColor = Color.LightGray
        End If
        RaiseEvent ScaleScrollChange()
    End Sub

    Private Sub opt200_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles opt200.CheckedChanged
        If opt200.Checked = True Then
            mvarxyScale = 0.5
            opt200.BackColor = Color.LightBlue
        Else
            opt200.BackColor = Color.LightGray
        End If
        RaiseEvent ScaleScrollChange()
    End Sub

    Private Sub pnlStuff_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles pnlStuff.Paint

    End Sub

    Private Sub ZoomControl_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
End Class
